window.onload = function() {
    var regtel = /^\d{11}$/; //手机号码的正则表达式
    var regqq = /^[1-9]\d{4,}$/;
    var regnc = /^[\u4e00-\u9fa5]{2,8}$/;
    var regmes = /^\d{6}$/;
    var regpwd = /^[a-zA-Z0-9_-]{6,16}$/;
    var tel = document.querySelector('#tel');
    var qq = document.querySelector("#qq");
    var nc = document.querySelector("#nc");
    var mes = document.querySelector("#mes");
    var pwd = document.querySelector("#pwd");
    var surepwd = document.querySelector("#surepwd");
    regexp(tel, regtel); //手机号码
    regexp(qq, regqq); //qq
    regexp(nc, regnc); //昵称
    regexp(mes, regmes); //短信验证
    regexp(pwd, regpwd); //密码框

    function regexp(ele, reg) {
        ele.onclick = function() {
            this.style.border = '1px solid pink';
            this.style.background = 'rgba(0,0,0,0.1)'
        };

        ele.onblur = function() {
            this.style.background = 'rgba(0,0,0,0.0)'
            this.style.border = '1px solid #ccc';
            if (reg.test(this.value)) {
                // console.log('正确的');
                this.nextElementSibling.className = 'success';
                this.nextElementSibling.innerHTML = '<i class="success_icon"></i>恭喜您输入正确';
            } else {
                // console.log('不正确的');
                this.nextElementSibling.className = 'error';
                this.nextElementSibling.innerHTML = '<i class="error_icon"></i>格式不正确，请从新输入';
            }
        }
    };

    surepwd.onblur = function() {
        if (this.value == pwd.value) {
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = '<i class="success_icon"></i>恭喜您输入正确';
        } else {
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = '<i class="error_icon"></i>两次密码输入不一致';
        }
    }


};